import type { Recordable } from 'vite-plugin-mock'

export const accessTokens = {
  admin: 'admin-accessToken',
  editor: 'editor-accessToken',
  test: 'test-accessToken'
}

export function vertifyToken(headers: Recordable) {
  const accessToken = headers['authorization']
  for (const key in accessTokens) {
    if (`Bearer ${accessTokens[key]}` === accessToken) {
      return { username: key, roles: [key] }
    }
  }
  return { code: 500, message: '无效的token' }
}
